<template>
<div v-show="total">
<!--  <input type="checkbox" name="matter" id="" :checked="isAll" @change="checkAll">-->
  <input type="checkbox" name="matter" id="" v-model="isAll">
  &nbsp;已完成 <span>{{doneTotal}}</span> / 全部 <span>{{total}}</span>
  <button @click="clearAll">清除已完成任务</button>
</div>
</template>

<script>
  export default {
    name: "Footer",
    props:['todos','checkAllTodo','clearAllTodo'],
    methods:{
      /*checkAll(e){
        console.log(e.target.checked)
        this.checkAllTodo(e.target.checked)
      }*/
      clearAll(){
        if(confirm('确认清除已完成任务吗？')){
          this.clearAllTodo()
        }
      }
    },
    computed:{
      total(){
        return this.todos.length
      },
      doneTotal(){
       /* const x = this.todos.reduce((pre,current)=>{
          console.log("@pre："+pre+"   @current：",current)
          return pre+(current.done?1:0)
        },0)
        console.log("###",x)*/
        return this.todos.reduce((pre,todo)=>pre+(todo.done?1:0),0)
      },
      isAll:{
        get(){
          return this.total === this.doneTotal&&this.total>0
        },
        set(value){
          this.checkAllTodo(value)
        }
      }
    }
  }
</script>

<style scoped lang="less">
div{
  width: 95%;
  margin: auto;
  margin-top: 10px;
  //border: 1px solid rgba(87, 87, 87, 0.3);
  button{
    background-color: #d9534f;
    float: right;
    padding: 3px 10px;
    color: white;
    border: 1px solid #d43f3a;
    border-radius: 5px;
    cursor: pointer;
    &:hover{
     background-color: #c9302c;
     border: 1px solid #ac2925;
   }
}
}
</style>
